package com.zhb.designmode.creationmode.single;

/**
 * 懒汉式
 */
public class Lazy {

    private static volatile Lazy lazy;

    private Lazy() {}

    public static Lazy getInstance(){
        if(null == lazy){
            synchronized (Lazy.class){
                if(null == lazy){
                    return new Lazy();//指令重排序有可能导致返回一个不完全构造好的对象，因此volatile修饰成员变量
                }
            }
        }
        return lazy;
    }
}

